package com.zengde.ai_sandbox.test.testthread.mathteacher;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DriverByThreadPool {

    public static void main(String[] args) {
        MathTeacher mathTeacher = new MathTeacher();

        ExecutorService executorService = Executors.newCachedThreadPool();
        //2个加线程
        for (int i = 0; i < 2; i++) {
            executorService.submit(() -> {
//                while (true) mathTeacher.add();
                mathTeacher.add();

            });
        }
        ;

        //2个减线程
        for (int i = 0; i < 2; i++) {
            executorService.submit(() -> {
//                while (true) mathTeacher.sub();
                mathTeacher.sub();
            });
        }

        executorService.shutdown();

    }

}
